

#ifndef __VIDEO_FILES_H
#define __VIDEO_FILES_H

class VideoFiles
{
	std::vector<std::string> files;

public:

	VideoFiles(const std::string &path) {

		Initialise( path );
	}

	virtual  ~VideoFiles() {

		files.resize(0);

	}

	std::string GetRandom() const {

		return files[ rand() % files.size() ];
	}

private:

	void Initialise(const std::string &path) {

#if defined(WIN32)

		/*** windows directory reading API ***/

		struct _finddata_t fi;
		intptr_t dir = _findfirst( (path + std::string("\\*")).c_str(), &fi );
		
		if(dir != -1) {
			if(std::string( fi.name ).find(".snut") != std::string::npos)
				files.push_back( path + "\\" + fi.name  );
			
			while( _findnext( dir, &fi ) == 0)
				if(std::string( fi.name ).find(".snut") != std::string::npos)
					files.push_back( path + "\\" + fi.name  );

			_findclose( dir );
		}
#else

		/*** POSIX directory reading API ***/

		dirent *ent;
		DIR *dir = opendir( path.c_str() );

		while(dir && (ent = readdir( dir )))
			if(std::string( ent->d_name ).find(".snut") != std::string::npos)
				files.push_back( std::string( path + "\\" + ent->d_name ) );

		closedir( dir );

#endif /*** HAS_DIRENT_H ***/

		
		if(files.size() == 0)
			throw Exception("No test files found!");

	}
};

#endif /*** __VIDEO_FILES_H ***/

